// display the max sum of any non-empty subsequence of a given list of integers

#include <iostream>
#include <vector>
using namespace std;

int max_subsequence_sum(vector<int> const& a, const int no_of_elements)
{
  int total_sum = 0;
  int largest_number = a[0];

  for (int i = 0; i < no_of_elements; ++i) {
    if (a[i] > largest_number) {
      largest_number = a[i];
    }

    if (a[i] > 0) {
      total_sum += a[i];
    }
  }

  if (largest_number > 0) {
    return total_sum;
  }

  return largest_number;
}

int main()
{
  int no_of_elements;
  cin >> no_of_elements;
  vector<int> a(no_of_elements);

  for (int i = 0; i < no_of_elements; ++i) {
    cin >> a[i];
  }

  cout << max_subsequence_sum(a, no_of_elements);

  return 0;

}